<template>
	<view class="beInHospital">
		<view class="list">
			<scroll-view class="scroll-view_H" scroll-y="true" style="height: calc(100vh - 118rpx);">
				<view class="noCard" v-if="dataList.length == 0">
					<view class="images">
						<img src="@/static/images/noCard.png" alt="">
						<view>
							未查询到信息
						</view>
					</view>
				</view>
				<view v-else>
					<view class="items" v-for="(item,index) in dataList" :key="index">
						<view class="title">
							<text>李木子</text>
							<view class="operate">
								编辑
								<view class="hidenView" v-if="false">
									<view class="listt border">
										修改住院人信息
									</view>
									<view class="listt">
										删除住院记录
									</view>
								</view>
							</view>
						</view>
						<view class="name">
							<text class="left">科室</text>
							<text>眼科</text>
						</view>
						<view class="icd">
							<text class="left">病区</text>
							<text>住院A区</text>
						</view>
						<view class="time">
							<text class="left">床位</text>
							<text>A1294</text>
						</view>
						<view class="dept">
							<text class="left">医生</text>
							<text>张三三</text>
						</view>
						<view class="dept">
							<text class="left">住院号</text>
							<text>27108317</text>
						</view>
						<view class="dept">
							<text class="left">登记时间</text>
							<text>2022-02-24 13:22:45</text>
						</view>
						<view class="dept border">
							<text class="left">押金余额</text>
							<text class="icdtext">0.00</text>
						</view>
						<view class="btns">
							<text>押金缴纳</text>
							<text>日清单查询</text>
							<text>押金记录</text>
						</view>
					</view>
				</view>

			</scroll-view>
		</view>
		<view class="footer">
			<u-button type="primary" style="width:90%;" @click="inHospitalReg">入院登记</u-button>
		</view>
		<!-- 切换就诊人 -->
		<u-popup :show="showVisitCard" :round="10" :safeAreaInsetBottom="true" mode="bottom">
			<switchVisitCard :visitData="visitList" :relations="relationTrans" @closeVisit="close" />
		</u-popup>
	</view>
</template>

<script>
	import {
		getInpatientInfo
	} from "@/api/beInHospital/index.js"
	import {
		getPatientBaseList
	} from "@/api/card/index.js"
	import switchVisitCard from '@/components/switchVisitCard/index.vue';
	import {
		getDictType
	} from "@/api/system/public.js";

	export default {
		components: {
			switchVisitCard,
		},
		data() {
			return {
				infoData: {},
				visitList: [],
				showVisitCard: false,
				relationTrans: {},
				hospitalInfor: {},
				dataList: []
			}
		},
		onLoad(options) {
			if (uni.getStorageSync('currentVisitCard')) {
				this.infoData = JSON.parse(uni.getStorageSync('currentVisitCard'))
				this.checkPersonInfo()
			}
			this.getCardList()
			this.getDict()
		},
		methods: {
			/* 查询当前就诊人入院信息 */
			checkPersonInfo() {
				let obj = {
					name: this.infoData.name,
					idNum: this.infoData.idNum
				}
				getInpatientInfo(obj).then(res => {
					if (res.code == 200) {

					}
					console.log(res)
				}).catch(error => {
					this.dataList = []
					/* 没有住院信息跳转入院登记 */
					// uni.navigateTo({
					// 	url: '/pages/beInHospital/register'
					// })
				});
			},
			
			/* 获取接真人列表 */
			getCardList() {
				let openid = uni.getStorageSync('openid') || ''
				let params = {
					hospitalCode: JSON.parse(uni.getStorageSync('hospital')).hospitalCode,
					openId: openid,
				}
				getPatientBaseList(params).then(res => {
					if (res.code == 200) {
						this.visitList = res.rows
					}
				});
			},
			close() {
				if (uni.getStorageSync('currentVisitCard')) {
					this.infoData = JSON.parse(uni.getStorageSync('currentVisitCard'))
					this.checkPersonInfo()
				}
				this.showVisitCard = false
			},
			inHospitalReg(){
				this.showVisitCard = true
			},
			/* 字典 */
			getDict() {
				getDictType({
					dictType: 'sys_relation'
				}).then(res => {
					console.log(res)
					if (res.code == 200) {
						res.rows.forEach(item => {
							this.relationTrans[item.dictValue] = item.dictLabel
						})
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background-color: rgb(245, 245, 245);
	}
	
	.noCard {
		width: 100%;
		text-align: center;
		color: #666666;
		padding: 24rpx 0 0 0;
		margin-top: 72rpx;
		color: #808080;
	
		.images {
			width: 100%;
			margin-bottom: 40rpx;
			color: #666666;
	
			img {
				width: 55%;
				text-align: center;
			}
		}
	}

	.footer {
		background-color: #fff;
		position: fixed;
		width: 100%;
		bottom: 0;
		left: 0;
		padding: 30rpx 0;
	}

	.list {
		padding: 24rpx;
		margin: 0 auto;

		.items {
			background-color: #fff;
			border-radius: 8px;

			.title {
				padding: 24rpx;
				display: flex;
				font-size: 32rpx;
				font-weight: 600;
				align-items: center;
				border-bottom: 1rpx solid #eee;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.operate {
					font-weight: 400;
					font-size: 28rpx;
					color: #4D8EFF;
					position: relative;

					.hidenView {
						color: #333;
						position: absolute;
						top: 48rpx;
						right: 0;
						font-size: 26rpx;
						background-color: #fff;
						box-shadow: 2px 2px 2px 2px #eee;
						padding: 2px;
						border-radius: 4px;

						.listt {
							white-space: nowrap;
							padding: 12rpx;
						}

						.border {
							border-bottom: 1rpx solid #eee;
						}
					}
				}
			}

			.border {
				border-bottom: 1rpx solid #eee;
			}

			.btns {
				display: flex;
				justify-content: space-around;
				align-items: center;
				padding: 20rpx;
				color: #4D8EFF;
			}

			.name,
			.icd,
			.time,
			.dept {
				display: flex;
				justify-content: space-between;
				padding: 12rpx 24rpx;
				font-size: 28rpx;

				.left {
					color: #999;
					width: 130rpx;
				}

				.icdtext {
					flex: 1;
					color: #FF6430;
					text-align: right;
					font-size: 36rpx;
				}
			}
		}
	}
</style>